<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue学习</title>
    <script src="../assets/vue.js"></script>
</head>
<body>
<h1>vue watch函数</h1>
<hr>
<div id="app">
    <p>今日温度：{{ grade }}度</p>
    <p>穿衣指数：{{ cloth }}</p>
    <p><button @click="add">升高温度</button><button @click="down">降低温度</button></p>
</div>
<script>
    var app = new Vue({
        el:'#app',
        data:{
            grade:10,
            cloth:'夹克牛仔裤'
        },
        methods:{
            add:function(){
                this.grade++
            },
            down:function(){
                this.grade--
            }
        },
        /*watch:{
            grade:function(n,o){
                if(n>=20){
                    this.cloth = '短裤背心'
                }else{
                    this.cloth = '夹克牛仔裤'
                }
            }
        }*/
    })

    app.$watch('grade',function(n,o){
        if(n>=20){
            this.cloth = '短裤背心'
        }else{
            this.cloth = '夹克牛仔裤'
        }
    })
</script>
</body>
</html>